package com.sp.reactive;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;

import java.util.Optional;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-04-16 15:30:15
 */
public class MonoTest {

    @Test
    public void test4() {
        Mono.just("hello")
                .concatWith(Mono.error(new IllegalArgumentException("aaa")))
                .onErrorReturn("default")
                .subscribe(System.out::println);
    }

    @Test
    public void test3() {
        Mono.just("hello")
                .concatWith(Mono.error(new IllegalArgumentException("aaa")))
                .subscribe(System.out::println, System.err::println);
    }

    @Test
    public void test2() {
        Mono.create(monoSink -> {
            monoSink.success("Hello");
        }).subscribe(System.out::println);
    }

    @Test
    public void test1() {
        Mono.justOrEmpty(Optional.of("Hello"))
                .subscribe(System.out::println);
    }
}
